#sprotgame.py

from random import random 

def printInfo():
    print("程序模拟选手间的比赛")
    print("程序运行请按步骤输入数据")

def getInputs():
    a = float(input("请输入1号选手的能力值（0-1）："))
    b = float(input("请输入2号选手的能力值（0-1）："))
    n = int(input("请输入模拟比赛的场次："))
    return a,b,n

def simGames(n,proA,proB):
    winA,winB = 0,0
    for i in range(n):
        scoreA,scoreB = oneGame(proA,proB)
        if scoreA > scoreB:
            winA += 1
        else:
            winB += 1
    return winA,winB

def oneGame(probA,probB):
    scoreA,scoreB = 0,0
    servling = 'A'
    while not gameOver(scoreA,scoreB):
        if servling == 'A':
            if random() < probA:
                scoreA += 1
            else:
                servling = 'B'
        else:
            if random() < probB:
                scoreB += 1
            else:
                servling = 'A'
        return scoreA,scoreB

def gameOver(a,b):
    return a == 15 or b == 15

def printSummary(winA,winB,n):
    print("分析开始，共模拟{}场比赛".format(n))
    print("选手A获胜{}场比赛，占比{:0.1%}".format(winA,winA/n))
    print("选手B获胜{}场比赛，占比{:0.1%}".format(winB,winB/n))

def main():
    printInfo()
    proA,proB,n = getInputs()
    winA,winB = simGames(n,proA,proB)
    printSummary(winA,winB,n)

main()